#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
//TCP服务器用到的
#include <QTcpServer>
#include <QTcpSocket>
#include <QNetworkConfigurationManager>
#include <QMessageBox>
#include <QDateTime>
#include <iostream>
#include <QString>
#include <QDebug>
#include <string>

//TCP客户端用到的
#include <QThread>
#include "network.h"


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_toolButton_start_clicked();

    void on_toolButton_close_clicked();

    void on_toolButton_connect_clicked();

    void on_toolButton_disconnect_clicked();

    void on_toolButton_send_clicked();

    void on_toolButton_exit_clicked();

    void on_checkBox_clientAutoTest_clicked();

    void on_toolButton_udpTest_clicked();

    //扩展
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::MainWindow *ui;

public:
    QTcpServer *tcpServer = nullptr;
    QTcpSocket *tcpSocket = nullptr;
    QList<QTcpSocket*> tcpSocketList;

    //处理客户端
    Network networkClient;

    //处理服务器
    Network networkServer;

    //检测IP地址合法性
    bool checkIpAddressIsVaild(QString strIpAdress);

    //控制客户端与服务器按钮之间的切换
    void clientButtonStateFunc();
    void serverButtonStateFunc();


    //扩展
    QString stringToHex(const QString &input);
    QString hexToString(const QString &hexInput);
public slots:
    //tcp服务器连接
    void tcpServerConnected();
    //客户端断开
    void clientDisconnected();
    //读取所有数据
    void readAllData();

    //等待客户端连接
    void newConnection();
};
#endif // MAINWINDOW_H
